import { ElMessage } from 'element-plus';

export const validateFileType = (
  file: File,
  types: string[] = [
    'image/jpeg',
    'image/png',
    'image/gif',
    'image/jpg',
    'image/bmp',
    'image/svg+xml',
    'image/webp'
  ]
): boolean => {
  if (!types.includes(file.type)) {
    ElMessage.error('上传的图片格式不支持!');
    return false;
  }
  return true;
};

// 2MB
export const validateFileSize = (file: File, size: number = 2): boolean => {
  if (file.size > 1024 * 1024 * size) {
    ElMessage.error(`上传的图片大小不能超过${size}MB`);
    return false;
  }
  return true;
};
